package com.apps.java.javanote02;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class _25网络编程TCP接收数据 {
    public static void main(String[] args) throws IOException {

        //接收数据
        //创建服务器端的Socket对象(ServerSocket)
        //ServerSocket(int port)创建绑定到指定端口的服务器套接字
        ServerSocket serSo = new ServerSocket(10000);

        //Socket accept()：倾听要连接到此套接字并接受它
        Socket acc = serSo.accept();

        //获取输入流，读数据，并把数据显示在控制台
        InputStream stream = acc.getInputStream();
        byte[] bys = new byte[1024];
        int len = stream.read(bys);

        String data = new String(bys,0,len);

        System.out.println("数据是：" + data);

        //关闭资源
        acc.close();
        serSo.close();

    }
}
